home *** CD-ROM | disk | FTP | other *** search
/ Amiga Developer CD 2.1 / Amiga Developer CD v2.1.iso / NDK / NDK_2.0 / NDK2.0-2 / NewIFF / modules / getdisplay.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-11-19  |  5.1 KB  |  209 lines

  1.  
  2. /*----------------------------------------------------------------------*
  3.  * GETDISPLAY.C  Support routines for reading/displaying ILBM files.
  4.  * (IFF is Interchange Format File.)
  5.  *
  6.  * Based on code by Jerry Morrison and Steve Shaw, Electronic Arts.
  7.  * This software is in the public domain.
  8.  * Modified for iffparse.library by CBM 04/90
  9.  * This version for the Commodore-Amiga computer.
  10.  *----------------------------------------------------------------------*/
  11.  
  12. #include "iffp/ilbm.h"
  13. #include "iffp/packer.h"
  14. #include "iffp/ilbmapp.h"
  15.  
  16. extern struct Library *GfxBase;
  17.  
  18. /* showilbm
  19.  *
  20.  * Passed an ILBMInfo initilized with with a not-in-use ParseInfo.iff
  21.  *   IFFHandle and desired propchks, collectchks, stopchks, and a filename,
  22.  *   will load and display an ILBM, initializing ilbm->Bmhd, ilbm->camg,
  23.  *   ilbm->scr, ilbm->win, ilbm->vp, ilbm->srp, ilbm->wrp,
  24.  *   ilbm->colortable, and ilbm->ncolors.
  25.  *
  26.  *   Note that ncolors may be more colors than you can LoadRGB4.
  27.  *   Use MIN(ilbm->ncolors,MAXAMCOLORREG) for color count if you change
  28.  *   the colors yourself using 1.3/2.0 functions.
  29.  *
  30.  * Returns 0 for success or an IFFERR (libraries/iffparse.h)
  31.  */
  32.  
  33. LONG showilbm(struct ILBMInfo *ilbm, UBYTE *filename)
  34. {
  35. LONG error = 0L;
  36.  
  37.     if(!(ilbm->ParseInfo.iff))    return(CLIENT_ERROR);
  38.  
  39.     if(!(error = openifile((struct ParseInfo *)ilbm, filename, IFFF_READ)))
  40.     {
  41.     D(bug("showilbm: openifile successful\n"));
  42.  
  43.     error = parseifile((struct ParseInfo *)ilbm,
  44.                 ID_FORM, ID_ILBM,
  45.                 ilbm->ParseInfo.propchks,
  46.                 ilbm->ParseInfo.collectchks,
  47.                 ilbm->ParseInfo.stopchks);
  48.  
  49.     if((!error)||(error == IFFERR_EOC)||(error == IFFERR_EOF))
  50.         {
  51.         D(bug("showilbm: parseifile successful\n"));
  52.  
  53.         if(contextis(ilbm->ParseInfo.iff,ID_ILBM,ID_FORM))
  54.         {
  55.             if(error = createdisplay(ilbm))
  56.             {
  57.             deletedisplay(ilbm);
  58.             }
  59.         }
  60.         else
  61.         {
  62.         message(SI(MSG_IFFP_NOILBM));
  63.         error = NOFILE;
  64.         }
  65.         }
  66.     if(error)    closeifile((struct ParseInfo *)ilbm);
  67.     }
  68.     return(error);
  69. }
  70.  
  71.  
  72. /* unshowilbm
  73.  *
  74.  * frees and closes everything alloc'd/opened by showilbm
  75.  * returns BOOL Success under V36 and above, always TRUE under <V36
  76.  */
  77. BOOL unshowilbm(struct ILBMInfo *ilbm)
  78. {
  79.     if(deletedisplay(ilbm))
  80.         {
  81.         closeifile((struct ParseInfo *)ilbm);
  82.         return(TRUE);
  83.         }
  84.     else return(FALSE);
  85. }
  86.  
  87.  
  88.  
  89. /* createdisplay
  90.  *
  91.  * Passed a initialized ILBMInfo with parsed IFFHandle (chunks parsed,
  92.  * stopped at BODY),
  93.  * opens/allocs the display and colortable, and displays the ILBM.
  94.  *
  95.  * If successful, sets up ilbm->Bmhd, ilbm->camg, ilbm->scr, ilbm->win,
  96.  *   ilbm->vp,  ilbm->wrp, ilbm->srp and also ilbm->colortable and
  97.  *   ilbm->ncolors.
  98.  *
  99.  * Note that ncolors may be more colors than you can LoadRGB4.
  100.  * Use MIN(ilbm->ncolors,MAXAMCOLORREG) for color count if you change
  101.  *   the colors yourself using 1.3/2.0 functions.
  102.  *
  103.  * Returns 0 for success or an IFFERR (libraries/iffparse.h)
  104.  */
  105.  
  106. LONG createdisplay(struct ILBMInfo *ilbm)
  107.     {
  108.     int error;
  109.  
  110.     D(bug("createdisplay:\n"));
  111.  
  112.     error             = getdisplay(ilbm);
  113.  
  114.     D(bug("createdisplay: after getdisplay, error = %ld\n", error));
  115.  
  116.     if(!error)     error     = loadbody(ilbm->ParseInfo.iff,
  117.                         &ilbm->scr->BitMap,&ilbm->Bmhd);
  118.  
  119.     D(bug("createdisplay: after loadbody, error = %ld\n", error));
  120.  
  121.     if(!error)
  122.         { 
  123.         if(!(getcolors(ilbm)))
  124.            LoadRGB4(ilbm->vp, ilbm->colortable,
  125.                 MIN(ilbm->ncolors,MAXAMCOLORREG));
  126.         }
  127.     if(error)  deletedisplay(ilbm);
  128.     return(error);
  129.     }
  130.  
  131.  
  132. /* deletedisplay
  133.  *
  134.  * closes and deallocates created display and colors
  135.  * returns BOOL Success under V36 and above, always TRUE under <V36
  136.  */
  137. BOOL deletedisplay(struct ILBMInfo *ilbm)
  138.     {
  139.     if(freedisplay(ilbm))
  140.         {
  141.         freecolors(ilbm);
  142.         return(TRUE);
  143.         }
  144.     else return(FALSE);
  145.     }
  146.  
  147.  
  148.  
  149. /* getdisplay
  150.  *
  151.  * Passed an initialized ILBMInfo with a parsed IFFHandle (chunks parsed,
  152.  * stopped at BODY),
  153.  * gets the dimensions and mode for the display and calls the external
  154.  * routine opendisplay().  Our opendisplay() is in the screen.c
  155.  * module.  It opens a 2.0 or 1.3, ECS or non-ECS screen and window.
  156.  * It also does 2.0 overscan centering based on the closest user prefs.
  157.  *
  158.  * If successful, sets up ilbm->Bmhd, ilbm->camg, ilbm->scr, ilbm->win,
  159.  *   ilbm->vp, ilbm->wrp, ilbm->srp
  160.  *
  161.  * Returns 0 for success or an IFFERR (libraries/iffparse.h)
  162.  */
  163. LONG getdisplay(struct ILBMInfo *ilbm)
  164.     {
  165.     struct IFFHandle *iff;
  166.     BitMapHeader *bmhd;
  167.     ULONG                modeid;
  168.     UWORD                wide, high, deep;
  169.  
  170.  
  171.     if(!(iff=ilbm->ParseInfo.iff))    return(CLIENT_ERROR);
  172.  
  173.     if(!(bmhd = (BitMapHeader *)findpropdata(iff, ID_ILBM, ID_BMHD)))
  174.         {
  175.         message (SI(MSG_IFFP_NOBMHD));
  176.         return(IFFERR_SYNTAX);
  177.         }
  178.  
  179.     *(&ilbm->Bmhd)    = *bmhd;
  180.  
  181.         wide = (RowBytes(bmhd->w)) >= (RowBytes(bmhd->pageWidth)) ?
  182.                 bmhd->w : bmhd->pageWidth;
  183.         high = MAX(bmhd->h, bmhd->pageHeight);
  184.         deep = MIN(bmhd->nPlanes,MAXAMDEPTH);
  185.  
  186.     ilbm->camg = modeid = getcamg(ilbm);
  187.  
  188.     /*
  189.      * Open the display
  190.      */
  191.     if(!(opendisplay(ilbm,wide,high,deep,modeid)))
  192.         {
  193.         message(SI(MSG_IFFP_NODISPLAY));
  194.         return(1);
  195.         }
  196.     return(0);
  197.     }
  198.  
  199.  
  200. /* freedisplay
  201.  *
  202.  * closes and deallocates display from getdisplay (not colors)
  203.  * returns BOOL Success under V36 and above, always TRUE under <V36
  204.  */
  205. BOOL freedisplay(struct ILBMInfo *ilbm)
  206.     {
  207.     return(closedisplay(ilbm));
  208.     }
  209.